package suo;


import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

public class SqlSessFactoryBuilder {
    private Configuration configuration;

    public SqlSessFactoryBuilder(){
        this.configuration=new Configuration();
    }

    public SqlSessionFactory build(InputStream inputStream) throws DocumentException, PropertyVetoException, ClassNotFoundException {
        //解析输入流，封装成Configuration对象
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder(configuration);
        configuration = xmlConfigBuilder.parseXML(inputStream);

        //把Configurat作为参数生成SqlSessionFactory
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return defaultSqlSessionFactory;
    }
}
